﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;

public partial class Controls_HomePage_ctrHomepageInitContent : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
          //  this.SetInitData();
        }
    }

    private void SetInitData()
    {
        int nCurrentLanguage = Support.GetCurrentLanguage();
        int nDefaultLanguage = Support.GetDefaultLanguage();
        int nItemView = 4;
        int nPageCount = 0;
        int nPageSize = 4;
        int nStatus = 1;
        int nItemID = 0;
        int nPageIndex = 1;
        string sInitTrunscate = "";

        // About Us
        StaticPages objStatic = new StaticPages();
        int nAboutID = objStatic.GetIDbyPageCode("giới-thiệu");
        objStatic.LoadById(nAboutID);
        btnImageAboutUs.ImageUrl = Config.ROOT + Config.IMAGE_STATICPAGE_DEFAULT_UPLOAD + objStatic.Data.Images;
        lnkAboutUs.NavigateUrl = Config.ROOT + Pages.FrontEnds.STATIC_PAGE + "?" + Config.PAGE_ID + "=" + nAboutID;


        // Tranh Tung
        NewsCategory objCategory = new NewsCategory();
        objCategory.LoadById(18);
        NewsCategory objTopicCategory = new NewsCategory();
        objTopicCategory.LoadById(23);

       

        int nTranhTungID = 33;
        
        News objNews = new News();
        DataTable dtbNews = new DataTable();
        dtbNews = objNews.Search(nItemView, nItemID, string.Empty, nTranhTungID, nDefaultLanguage, nCurrentLanguage, nStatus, nPageIndex, nPageSize, ref nPageCount);

        imgTranhTung.ImageUrl = Config.ROOT + Config.IMAGE_NEWS_DEFAULT_UPLOAD + ConvertData.ConvertToString(dtbNews.Rows[0]["Image"]);
        lnkTranhtungTitle.Text = ConvertData.ConvertToString(dtbNews.Rows[0]["NewsTitle"]);
        lnkTranhtungTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" +Config.NEWS_ID + "=" +  ConvertData.ConvertToString(dtbNews.Rows[0]["NewsID"]) ;
        string sTranhTungInit = ConvertData.ConvertToString(dtbNews.Rows[0]["InitContent"]);
        if (sTranhTungInit.Length > 220)
            sTranhTungInit = ConvertData.TruncateString(sTranhTungInit, 220) + "...";
        lblInitTranhTung.Text = sTranhTungInit; 
        // Sub Tranh tung
        lnkTranhtungTitle2.Text = ConvertData.ConvertToString(dtbNews.Rows[1]["NewsTitle"]);
        lnkTranhtungTitle2.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbNews.Rows[1]["NewsID"]);  
        lnkTranhtungTitle3.Text = ConvertData.ConvertToString(dtbNews.Rows[2]["NewsTitle"]);
        lnkTranhtungTitle3.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbNews.Rows[2]["NewsID"]);  

        lnkTranhtungTitle4.Text = ConvertData.ConvertToString(dtbNews.Rows[3]["NewsTitle"]);
        lnkTranhtungTitle4.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbNews.Rows[3]["NewsID"]);  

        switch (nCurrentLanguage)
        {
            case 1:
                // About Us
                sInitTrunscate = objStatic.Data.InitContent1;
                lnkAboutUs.Text = objStatic.Data.PageName1;

                // Tranh tung
                lnkTranhTung.Text = objCategory.Data.Description1;
               
                // Topic
                lnkTopic.Text = objTopicCategory.Data.Description1;
                lnkConsult.Text = "Tư vấn pháp luật";
                lnkKysu.Text = "Ký sự";
                lnkDichvuPhaply.Text = "Dịch vụ pháp lý";
                lnkAboutUsTitle.Text = "Công ty Luật TNHH Hoàng Long (Hoang Long Law Co., Ltd)";
                break;
            case 2:
                // About Us
                sInitTrunscate = objStatic.Data.InitContent2;
                lnkAboutUs.Text = objStatic.Data.PageName2;

                // Tranh tung
                lnkTranhTung.Text = objCategory.Data.Description2;
                // Topic
                lnkTopic.Text = objTopicCategory.Data.Description2;
                lnkConsult.Text = "Legal Advice";
                lnkKysu.Text = "Memoir";
                lnkDichvuPhaply.Text = "Legal Services";
                lnkAboutUsTitle.Text = "Hoang Long Law Co., Ltd";
                break;
            case 3:
                // About Us
                sInitTrunscate = objStatic.Data.InitContent3;
                lnkAboutUs.Text = objStatic.Data.PageName3;

                // Tranh tung
                lnkTranhTung.Text = objCategory.Data.Description3;
                // Topic
                lnkTopic.Text = objTopicCategory.Data.Description3;
                lnkConsult.Text = "Legal Advice";
                lnkKysu.Text = "Memoir";
                lnkDichvuPhaply.Text = "Legal Services";
                lnkAboutUsTitle.Text = "Hoang Long Law Co., Ltd";
                break;

        }
        if (sInitTrunscate.Length >320)
        {
            lblInitContentAboutUs.Text = ConvertData.TruncateString(sInitTrunscate, 320);  
        }
        else
        {
            lblInitContentAboutUs.Text = sInitTrunscate;
        }

        // Topic
      
        int nTopicID = 27;

        News objTopic = new News();
        DataTable dtbTopic = new DataTable();
        dtbTopic = objTopic.Search(nItemView, nItemID, string.Empty, nTopicID, nDefaultLanguage, nCurrentLanguage, nStatus, nPageIndex, nPageSize, ref nPageCount);

        imgTopic.ImageUrl = Config.ROOT + Config.IMAGE_NEWS_DEFAULT_UPLOAD + ConvertData.ConvertToString(dtbTopic.Rows[0]["Image"]);
        lnkTopicTitle.Text = ConvertData.ConvertToString(dtbTopic.Rows[0]["NewsTitle"]);
        lnkTopicTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbTopic.Rows[0]["NewsID"]);
        string sTopicInit = ConvertData.ConvertToString(dtbTopic.Rows[0]["InitContent"]);
        if (sTopicInit.Length > 220)
            sTopicInit = ConvertData.TruncateString(sTopicInit, 220) + "...";
        lblTopicInitContent.Text = sTopicInit; 
        // Sub Topic
        lnkTopic2.Text = ConvertData.ConvertToString(dtbTopic.Rows[1]["NewsTitle"]);
        lnkTopic2.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbTopic.Rows[1]["NewsID"]);
        lnkTopic3.Text = ConvertData.ConvertToString(dtbTopic.Rows[2]["NewsTitle"]);
        lnkTopic3.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbTopic.Rows[2]["NewsID"]);
        lnkTopic4.Text = ConvertData.ConvertToString(dtbTopic.Rows[3]["NewsTitle"]);
        lnkTopic4.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbTopic.Rows[3]["NewsID"]);


        // Consulting

        int nConsulID = 41;

        News objConsult = new News();
        DataTable dtbConsult = new DataTable();
        dtbConsult = objConsult.Search(nItemView, nItemID, string.Empty, nConsulID, nDefaultLanguage, nCurrentLanguage, nStatus, nPageIndex, nPageSize, ref nPageCount);

        imgConsult.ImageUrl = Config.ROOT + Config.IMAGE_NEWS_DEFAULT_UPLOAD + ConvertData.ConvertToString(dtbConsult.Rows[0]["Image"]);
        lnkConsultTitle.Text = ConvertData.ConvertToString(dtbConsult.Rows[0]["NewsTitle"]);
        lnkConsultTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbConsult.Rows[0]["NewsID"]);
        string sConsultInit = ConvertData.ConvertToString(dtbConsult.Rows[0]["InitContent"]);
        if (sConsultInit.Length > 220)
            sConsultInit = ConvertData.TruncateString(sConsultInit, 220) + "...";
        lblInitConsult.Text = sConsultInit;
        // Sub Topic
        lnkConsult2 .Text = ConvertData.ConvertToString(dtbConsult.Rows[1]["NewsTitle"]);
        lnkConsult2.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbConsult.Rows[1]["NewsID"]);
        lnkConsult3.Text = ConvertData.ConvertToString(dtbConsult.Rows[2]["NewsTitle"]);
        lnkConsult3.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbConsult.Rows[2]["NewsID"]);
        lnkConsult4.Text = ConvertData.ConvertToString(dtbConsult.Rows[3]["NewsTitle"]);
        lnkConsult4.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbConsult.Rows[3]["NewsID"]);


        // Dich vu phap ly

        int nPhaply = 45;
        News objPhaply = new News();
        DataTable dtbPhaply = new DataTable();
        dtbPhaply = objPhaply.Search(nItemView, nItemID, string.Empty, nPhaply, nDefaultLanguage, nCurrentLanguage, nStatus, nPageIndex, nPageSize, ref nPageCount);

        imgDichvuPhaply.ImageUrl = Config.ROOT + Config.IMAGE_NEWS_DEFAULT_UPLOAD + ConvertData.ConvertToString(dtbPhaply.Rows[0]["Image"]);
        lnkDichvuPhaplyTitle.Text = ConvertData.ConvertToString(dtbPhaply.Rows[0]["NewsTitle"]);
        lnkDichvuPhaplyTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbPhaply.Rows[0]["NewsID"]);
        string sPhaplyInit = ConvertData.ConvertToString(dtbPhaply.Rows[0]["InitContent"]);
        if (sPhaplyInit.Length > 220)
            sPhaplyInit = ConvertData.TruncateString(sPhaplyInit, 220) + "...";
        lblDichvuPhaplyInitContent.Text = sPhaplyInit;
        // Sub Topic
        lnkDichvuPhaply2 .Text = ConvertData.ConvertToString(dtbPhaply.Rows[1]["NewsTitle"]);
        lnkDichvuPhaply2.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbPhaply.Rows[1]["NewsID"]);
        lnkDichvuPhaply3.Text = ConvertData.ConvertToString(dtbPhaply.Rows[2]["NewsTitle"]);
        lnkDichvuPhaply3.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbPhaply.Rows[2]["NewsID"]);
        lnkDichvuPhaply4.Text = ConvertData.ConvertToString(dtbPhaply.Rows[3]["NewsTitle"]);
        lnkDichvuPhaply4.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbPhaply.Rows[3]["NewsID"]);

        // Ky su
        int nKysu = 25;
        News objKysu = new News();
        DataTable dtbKysu = new DataTable();
        dtbKysu = objKysu.Search(nItemView, nItemID, string.Empty, nKysu, nDefaultLanguage, nCurrentLanguage, nStatus, nPageIndex, nPageSize, ref nPageCount);

        imgKysu.ImageUrl = Config.ROOT + Config.IMAGE_NEWS_DEFAULT_UPLOAD + ConvertData.ConvertToString(dtbKysu.Rows[0]["Image"]);
        lnkKysuTitle.Text = ConvertData.ConvertToString(dtbKysu.Rows[0]["NewsTitle"]);
        lnkKysuTitle.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbKysu.Rows[0]["NewsID"]);
        string sKysuInit = ConvertData.ConvertToString(dtbKysu.Rows[0]["InitContent"]);
        if (sKysuInit.Length > 220)
            sKysuInit = ConvertData.TruncateString(sKysuInit, 220) + "...";
        lblKySuInitContent.Text = sKysuInit;
        // Sub Topic
        lnkKysu2.Text = ConvertData.ConvertToString(dtbKysu.Rows[1]["NewsTitle"]);
        lnkKysu2.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbKysu.Rows[1]["NewsID"]);
        lnkKysu3.Text = ConvertData.ConvertToString(dtbKysu.Rows[2]["NewsTitle"]);
        lnkKysu3.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbKysu.Rows[2]["NewsID"]);
        lnkKysu4.Text = ConvertData.ConvertToString(dtbKysu.Rows[3]["NewsTitle"]);
        lnkKysu4.NavigateUrl = Config.ROOT + Pages.FrontEnds.NEWS_DETAIL + "?" + Config.NEWS_ID + "=" + ConvertData.ConvertToString(dtbKysu.Rows[3]["NewsID"]);
    
    }

    protected void btnImageAboutUs_Click(object sender, ImageClickEventArgs e)
    {
        StaticPages objStatic = new StaticPages();
        int nAboutID = objStatic.GetIDbyPageCode("giới-thiệu-công-ty");
        objStatic.LoadById(nAboutID);
        Response.Redirect(Config.ROOT + Pages.FrontEnds.STATIC_PAGE + "?" + Config.PAGE_ID + "=" + nAboutID);
    }
    protected void imgTopic_Click(object sender, ImageClickEventArgs e)
    {

    }
}
